/**
 * 
 */
package roboticsfmw.sample;

import roboticsfmw.annotation.HardwareRef;
import roboticsfmw.annotation.OnEvent;
import roboticsfmw.core.Processor;
import roboticsfmw.core.ProcessorException;

/**
 * @author Denys
 *
 */
public class CommandProcessor extends Processor {

	@HardwareRef(name="/hw/userIO")
	public UserIOHardwareProxy ioHw;
	
	private CommandEvent event;
	
	// SensorName = Sample Processor
	// polling interval = 1 sec.
	// Run Loop until turn off = true 
	public CommandProcessor() throws IllegalArgumentException {
		super("Sample Processor", 100, true);
	}

	/* (non-Javadoc)
	 * @see roboticsfmw.core.Processor#init()
	 */
	@Override
	public void init() throws ProcessorException {
		ioHw.sendCommand("Robot ready to receive commands!");
	}

	/* (non-Javadoc)
	 * @see roboticsfmw.core.Processor#shutdown()
	 */
	@Override
	public void shutdown() throws ProcessorException {
	}

	/* (non-Javadoc)
	 * @see roboticsfmw.core.ManagedComponent#loop(long)
	 */
	@Override
	public void loop(long i) {
		if (event!=null) {
			ioHw.sendCommand("Received Command: "+event.getCommand());
			event=null;
		}
	}

	@OnEvent(CommandEvent.class)
	public void OnCommandEvent(CommandEvent event) {
		this.event=event;
	}
	
}
